package com.rocksdata.mc.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.rocksdata.mc.R;

/**
 * Created by 陈堂正 on 2017/5/12.
 */

public abstract class BaseWidgetView extends RelativeLayout {
    protected RelativeLayout layoutHead;
    protected ImageView ivIcon;
    protected TextView tvName;
    protected TextView tvMore;
    protected ImageView ivHead;
    protected FrameLayout layoutContent;

    protected Context mContext;
    protected OnEnterAppListener onEnterAppListener;

    public BaseWidgetView(Context context) {
        this(context, null);
    }

    public BaseWidgetView(Context context, AttributeSet attrs) {
        super(context, attrs);
        mContext = context;
        init();
    }

    private void init(){
        LayoutInflater.from(mContext).inflate(R.layout.item_app_widget, this);
        layoutHead = (RelativeLayout) findViewById(R.id.layout_widget_head);
        ivIcon = (ImageView) findViewById(R.id.iv_widget_icon);
        tvName = (TextView) findViewById(R.id.tv_widget_name);
        tvMore = (TextView) findViewById(R.id.tv_widget_more);
        ivHead = (ImageView) findViewById(R.id.iv_widget_head);
        layoutContent = (FrameLayout) findViewById(R.id.layout_widget_content);
        View view = getContentView();
        layoutContent.addView(view);
        setupHeadView();
    }

    public abstract void setupHeadView();

    public abstract View getContentView();

    public abstract void bindData();

    public abstract void release();

    public void setOnEnterAppListener(OnEnterAppListener onEnterAppListener){
        this.onEnterAppListener = onEnterAppListener;
    }

    public interface OnEnterAppListener{
        void onEnterApp(int widgetType);
    }
}
